package com.manage.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.manage.common.R;
import com.manage.pojo.FlowerUser;
import com.manage.service.FlowerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 普通用户
 */
@CrossOrigin
@RestController
@RequestMapping("/flower-user")
public class FlowerUserController {

    @Autowired
    private FlowerUserService flowerUserService;


    /**
     * 查询所有用户
     * @return
     */
    @GetMapping("/list")
    public R list() {
        return R.success(flowerUserService.list());
    }

    /**
     * 禁用或启用用户
     */
    @GetMapping("/able")
    public R enable_disable(@RequestParam("status_btn") String status_btn,@RequestParam("userId") String userId){
        return R.success(flowerUserService.updateStatus(status_btn,userId),"修改状态成功");
    }

    /**
     * 根据用户名查询用户
     * @param userName
     * @return
     */
    @GetMapping("/search")
    public R search(@RequestParam("user_name") String userName){
        List<FlowerUser> list = flowerUserService.search(userName);
        return R.success(list,"查询成功！");
    }

    /**
     * 分页查询
     * @param current_page
     * @return
     */
    @GetMapping("/page")
    public R page(@RequestParam("current_page") Integer current_page){
        IPage<FlowerUser> page = flowerUserService.pageList(current_page);
        return R.success(page.getRecords());
    }

    @PutMapping("update_save")
    public R update_save(@RequestBody FlowerUser flowerUser){
        flowerUserService.updateById(flowerUser);
        return R.success("确定！");
    }

}

